#coding:utf-8

try: from pyh import *
except ImportError,e:
    print(
"""ImportError: %s \n Install :
 # wget http://pyh.googlecode.com/files/PyH-0.1.1.tar.gz
 # tar zxvf PyH-0.1.1.tar.gz
 # cd PyH-0.1.1
 # python setup.py install"""%e)
    exit()
import sys
reload(sys)
sys.setdefaultencoding('utf-8')



def res_html(desc, rows, item_name):
    page = PyH('monitor_results')
    page << '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
    myDiv = page << div()
    resultsTable = myDiv << table(border='1px', align="center")
    try:
        #表格标题， 数据监控项目名称
        resultsTableTtiletr = resultsTable << tr(bgcolor="aqua")
        resultsTableTtiletr << td(colspan='%s'%len(desc), align="center") << "<b>%s[%s]</b>" % (item_name, len(rows))
        #表格列头， 字段描述
        resultsTableColtr = resultsTable << tr(bgcolor="aqua")
        for i in desc:
            resultsTableColtr << td(i)
        n=0
        for row in rows:
            if n%2 == 0:
                objtr = resultsTable <<  tr(bgcolor="#EDF3FE")
            else:
                objtr = resultsTable <<  tr(bgcolor="white")
            n+=1
            for b in row:
                objtr << td(b)
    except Exception as e:
        myTable1 = myDiv << table(border='1px') << tr() << td('NULL',bgcolor="#EDF3FE")
    return page

